package a_producer;

public class Producer extends Thread{

    @Override
    public void run(){
        while(true){
            synchronized (Bread.lock){
                if(Bread.count == 0){
                    break;
                }else {
                    if (!Bread.flag) {
                        //没包子,生产包子
                        System.out.println("生产面包");
                        Bread.flag = true;
                        //唤醒消费者来消费 - notify()
                        Bread.lock.notify();
                    } else {
                        //有包子则不生产，进入等待状态
                        try {
                            Bread.lock.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        }
    }
}
